package cn.yuanqiao.web.controller.archive.tongji;

import cn.yuanqiao.archive.tongji.service.ZiDingYiTjService;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import com.alibaba.fastjson2.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zjj
 * @date 2023/8/15
 */
@RestController
@RequestMapping("/archive/tongji")
public class ZiDingYiTjController extends BaseController {

    @Autowired
    private ZiDingYiTjService ziDingYiTjService;

    /**
     * 获取门类
     * @return
     */
    @PostMapping("/getcategory")
    public AjaxResult getcategory(){
        List<Map<String, Object>> list = ziDingYiTjService.getCategoryList();
        return AjaxResult.success(list);
    }

    /**
     * 获取部门
     * @return
     */
    @PostMapping("/getdatatable")
    public AjaxResult getdatatable(@RequestBody JSONObject json){
        try {
            List<Map<String, Object>> list = null;
            Map map = new HashMap();
            map.put("x",json.getString("x"));
            map.put("y",json.containsKey("y") ? json.getString("y"):null);
            map.put("startTime",json.containsKey("startTime") ? json.getString("startTime"):null);
            map.put("endTime",json.containsKey("endTime") ? json.getString("endTime"):null);
            map.put("dept",json.containsKey("dept") ? json.getString("dept"):null);
            map.put("category",json.containsKey("category") ? json.getString("category"):null);
            if (StringUtils.isEmpty(json.getString("y"))) {
                list = ziDingYiTjService.getdataform(map);
            } else {
                list = ziDingYiTjService.getdatatable(map);
            }
            JSONObject object = new JSONObject();
            object.put("data",list);
            return AjaxResult.success(object);
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
        return AjaxResult.error();
    }
}
